home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-11 | 4.9 KB | 225 lines | [TEXT/CWIE] |
- // CMainWindow.cp -- window methods
-
- #include "CMainWindow.h"
-
- #include <UEnvironment.h>
- #include <UReanimator.h>
- #include <URegistrar.h>
- #include <LStream.h>
- #include <LTabGroup.h>
- #include <UAttachments.h>
- #include <LStaticText.h>
- #include <LAMStaticTextImp.h>
- #include <LGAStaticTextImp.h>
- #include <LEditText.h>
- #include <LAMEditTextImp.h>
- #include <LGAEditTextImp.h>
- #include <LSlider.h>
- #include <LAMTrackActionImp.h>
- #include <LGASliderImp.h>
- #include <CustomControls.h>
- #include <CTextUtils.h>
-
- #include "DDocData.h"
- #include "TemperatureCmds.h"
-
- const MessageT msgEditCentigrade = 'Edie';
- const MessageT msgEditFahrenheit = 'Edit';
- const MessageT msgCentSlider = 'Cenr';
-
- #define PPob_MainWindowID 201
- #define RidL_MainWindowID 201
-
- Boolean CMainWindow::sIsRegistered = false;
-
- //----------
- CMainWindow* CMainWindow::CreateMainWindow (
- LCommander* inSuperCommander,
- DDocData* inData)
- {
- if (!sIsRegistered) {
- RegisterClass ();
- }
-
- CMainWindow* window;
- window = (CMainWindow *)LWindow::CreateWindow(PPob_MainWindowID, inSuperCommander);
- window->ConnectToData (inData);
- return window;
- }
-
- //----------
- #define RegisterClasses(AbstractClass,AMImpClass,GAImpClass) \
- RegisterClass_(AbstractClass); \
- if (useAppearance) { \
- RegisterClassID_(AMImpClass, AbstractClass::imp_class_ID); \
- } else { \
- RegisterClassID_(GAImpClass, AbstractClass::imp_class_ID); \
- }
-
- //----------
- void CMainWindow::RegisterClass ()
- {
- Boolean useAppearance = UEnvironment::HasFeature (env_HasAppearance);
-
- RegisterClass_(CMainWindow);
-
- // register the pane classes we use
- RegisterClasses (LStaticText, LAMStaticTextImp, LGAStaticTextImp);
- RegisterClasses (LEditText, LAMEditTextImp, LGAEditTextImp);
- RegisterClasses (LSlider, LAMTrackActionImp, LGASliderImp);
- RegisterClasses (CControlPane, CustomControlImp, CustomControlImp);
-
- sIsRegistered = true;
- }
-
- //----------
- CMainWindow::CMainWindow (
- LStream* inStream)
- : LWindow (inStream)
- {
- }
-
- //----------
- CMainWindow::~CMainWindow ()
- {
- }
-
- //----------
- // This member function gets called once the containment hierarchy that contains
- // this pane has been built. It gives us a chance to get data members for
- // interesting subviews, and to do other operations now that our subviews exist.
- void CMainWindow::FinishCreateSelf ()
- {
- mEditCentigradeField = (LEditText*) FindPaneByID ('Edie');
- mEditCentigradeField->AddListener (this);
-
- mEditFahrenheitField = (LEditText*) FindPaneByID ('Edit');
- mEditFahrenheitField->AddListener (this);
-
- mCentSliderScroll = (LSlider*) FindPaneByID ('Cenr');
-
- mFahrBarBar = (CControlPane*) FindPaneByID ('Fahr');
-
-
- LTabGroup* tabGroup = new LTabGroup(this);
- mEditCentigradeField->SetSuperCommander(tabGroup); // becomes the active field
- mEditFahrenheitField->SetSuperCommander(tabGroup);
-
- UReanimator::LinkListenerToControls(this, this, RidL_MainWindowID);
- // "connect" self to our controls that we want to "listen" to
-
- // any additional initialization for your window:
- }
-
- //----------
- void CMainWindow::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddListener (this);
-
- mEditCentigradeField->SetValue (mData->GetCentigrade ());
- mEditFahrenheitField->SetValue (mData->GetFahrenheit ());
- mCentSliderScroll->SetValue (mData->GetCentigrade ());
- mFahrBarBar->SetValue (mData->GetFahrenheit ());
- }
-
- //----------
- void CMainWindow::DataChanged (
- long inDataID)
- {
- StopListening ();
-
- if (inDataID == idCentigrade) {
- if (!mEditCentigradeField->IsTarget ()) {
- mEditCentigradeField->SetValue (mData->GetCentigrade ());
- }
- }
- if (inDataID == idFahrenheit) {
- if (!mEditFahrenheitField->IsTarget ()) {
- mEditFahrenheitField->SetValue (mData->GetFahrenheit ());
- }
- }
- if (inDataID == idCentigrade) {
- mCentSliderScroll->SetValue (mData->GetCentigrade ());
- }
- if (inDataID == idFahrenheit) {
- mFahrBarBar->SetValue (mData->GetFahrenheit ());
- }
-
- StartListening ();
- }
-
- //----------
- void CMainWindow::ListenToMessage (
- MessageT inMessage,
- void* ioParam)
- {
- switch (inMessage) {
- case msgDataChanged:
- DataChanged ((long)ioParam);
- break;
-
- case msgEditCentigrade:
- mData->SetCentigrade (mEditCentigradeField->GetValue ());
- break;
-
- case msgEditFahrenheit:
- mData->SetFahrenheit (mEditFahrenheitField->GetValue ());
- break;
-
- case msgCentSlider:
- mData->SetCentigrade (mCentSliderScroll->GetValue ());
- break;
-
- default:
- ; // do something
- break;
- }
- }
-
- //----------
- Boolean CMainWindow::ObeyCommand (
- CommandT inCommand,
- void* ioParam)
- {
- Boolean cmdHandled = true;
-
- if (inCommand < 0) {
- // modal dialog has finished
-
- switch (-inCommand) {
- }
-
- } else {
- switch (inCommand) {
-
- default:
- cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
- break;
- }
- }
-
- return cmdHandled;
- }
-
- //----------
- void CMainWindow::FindCommandStatus (
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
-
- default:
- LWindow::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-